package com.houger.ddd.seckill.repository;

import com.houger.ddd.seckill.infra.entity.ActivityTemplateBasic;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Houger.
 * @date 2024年05月20日 11:02.
 */

@Repository
public interface ActivityTemplateBasicRepository extends JpaRepository<ActivityTemplateBasic,Long>, JpaSpecificationExecutor<ActivityTemplateBasic> {
    ActivityTemplateBasic findByTemplateCode(String templateCode);


    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update activity_template_basic set template_status = ?3 where id = ?1 and template_status=?2 and version=?4",nativeQuery=true)
    int updateTemplateStatus(Long id, int from, int to,Long version);

    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update activity_template_basic set template_status = ?3 where id = ?1 and template_status=?2",nativeQuery=true)
    int updateTemplateStatus(Long id, int from, int to);
}
